package com.dapeis.core.utils.json;

import java.lang.reflect.Type;
import java.util.Date;

import com.ag.utils.DateUtils;
import com.dapeis.core.utils.DBConfigUtils;
import com.dapeis.core.utils.StylistConstants;
import com.dapeis.domain.Order;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;

public class OrderGsonAdapter implements JsonSerializer<Order> {

    @Override
    public JsonElement serialize(Order src, Type typeOfSrc,
	    JsonSerializationContext context) {
	JsonObject json = new JsonObject();
	json.addProperty("ordreId", src.getId().toString());// 订单id
	json.addProperty("statusStr",
		StylistConstants.getOrderStatusStr(src));
	json.addProperty("status", src.getState());
	if (null != src.getTaskTime()) {
	    json.addProperty("taskTime", DateUtils.format(
		    DateUtils.YYYY_MM_DD_HH_MM_SS, new Date(
			    src.getTaskTime() * 1000)));
	} else {
	    json.addProperty("taskTime", new String());
	}
	if (null != src.getServerFinshTime()) {
	    json.addProperty("finshTime", DateUtils.format(
		    DateUtils.YYYY_MM_DD_HH_MM_SS,
		    new Date(src.getServerFinshTime() * 1000)));
	} else {
	    json.addProperty("finshTime", new String());
	}
	return json;
    }

}
